import React, { useEffect, useState } from 'react';
import { t } from '@lingui/macro';

export default function TotalPrice({ prices = [] }) {
  const [total, setTotal] = useState(0);

  useEffect(() => {
    const price = prices.reduce((acc, item) => {
      let sum = acc;
      sum += item.priceSum;
      return sum;
    }, 0);
    setTotal(price);
  }, [prices]);
  return (
    <span style={{ fontSize: 14, fontWeight: 500, marginLeft: 30 }}>
      {t`总金额: `}
      <span style={{ color: 'red' }}>{t`${total.toFixed(2)}`}</span>
    </span>
  );
}
